package com.lagou.sqlsession;

import com.lagou.config.Configuration;
import com.lagou.parse.SqlConfigBuilder;
import com.lagou.parse.XmlConfigBuilder;
import com.lagou.util.Resources;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * Created by seemygo on 2020/11/13.
 */
public class SqlSessionFactoryBuild {
    //利用工厂模式
    private Configuration configuration;

    public SqlSessionFactoryBuild() {
        this.configuration = configuration;
    }

    public SqlSessionFactory build(InputStream in) throws Exception {


        //1,将字节输入流解析  封装到configuration对象中
        XmlConfigBuilder xmlConfigBuilder=new XmlConfigBuilder(configuration);
        //构建者模式   构建出最终的configuration
        Configuration configuration= xmlConfigBuilder.parseXmlConfiguration(in);
        //2,通过configuration 创建SqlSessionFactory  创建生产sqlSessionFactory工厂
        return new DefaultSqlSessionFactory(configuration);
    }


}
